$(function() {
    $("#login").click(function () {
        $("#count_msg").html("");
        $("#password_msg").html("");
        let username = $("#count").val().trim();
        let password = $("#password").val().trim();
        var flag=true;
        if(username=="") {
            flag = false;
            $("#count_msg").html("用户名不能为空");
        }
        if(password==""||password==null) {
            flag = false;
            $("#password_msg").html("密码不能为空")
        }
        if (flag) {
            $.ajax({
                url:"http://localhost:8080/user/login.do",
                type:"get",
                data:{
                    "username":username,
                    "password":password
                },
                dataType : "json",
                success : function(data) {
                    if (data.status==0) {
                        let userId=data.data.id;
                        console.log(userId);
                        addCookie("userId",userId,0.5);
                        window.location.href="edit.html";
                    }else if (data.status == 1) {
                        $("#count_msg").html(data.msg)
                    }else if (data.status == 2) {
                        $("#password_msg").html(data.msg);
                    }
                },
                error:function(XMLHttpRequest,textStatus,errorThrown) {
                    alert("登陆失败,稍后重试")
                }
            })
        }
    })
})